<div id="tab9" class="tab">
    <div class="tab-labels">
        <div class="xian"></div>
        三者人伤
    </div>
    <div id="div2">
        <div style="border:1px solid #FF5722; padding-top: 10px;">
            <table class="layui-table" id="tabProduct6">
                <tr style="background:#4e73df;color: #fff;" class="ys">
                    <td style="width: 66px;">选择</td>
                    <!--<td>服务种类</td>-->
                    <td>姓名</td>
                    <td>性别</td>
                    <td>年龄</td>
                    <td>户籍性质</td>
                    <td>医疗机构</td>
                    <td>病案号</td>
                    <td>金额</td>
                    <td>核价金额</td>
                    <td>备注</td>
                </tr>
                {empty name="sanren"}
                <tr>
                    <td><input type="checkbox" style="width: 15px;height: 15px;display: block;" name="id"
                               readonly value=""></td>
                    <!--<td><input type="text" name="type" readonly></td>-->
                    <td><input type="text" name="name" readonly></td>
                    <td><input type="text" name="sex" readonly></td>
                    <td><input type="text" name="age" readonly></td>
                    <td><input type="text" name="quality" readonly></td>
                    <td><input type="text" name="nuit" readonly></td>
                    <td><input type="text" name="number" readonly></td>
                    <td><input type="text" name="money" readonly></td>
                    <td><input type="text" name="hejia" readonly></td>
                    <td><input type="text" name="beizhu" readonly></td>
                </tr>
                {/empty}
                {volist name='sanren' id="sanrens"}
                <tr>
                    <td><input type="checkbox" style="width: 15px;height: 15px;display: block;" name="id"
                               readonly value="{$sanrens.id}"></td>
                    <!-- <td><input type="text" name="type" readonly value="{$sanrens.type}"></td> -->
                    <td><input type="text" name="name" readonly value="{$sanrens.name}"
                               onclick="openDialogs2({$sanrens.id})"
                               style='text-decoration: underline;color:blue;cursor: pointer;'></td>
                    <td><input type="text" name="sex" readonly value="{$sanrens.sex}"></td>
                    <td><input type="text" name="age" readonly value="{$sanrens.age}"></td>
                    <td><input type="text" name="quality" readonly value="{$sanrens.quality}"></td>
                    <td><input type="text" name="nuit" readonly value="{$sanrens.nuit}"></td>
                    <td><input type="text" name="number" readonly value="{$sanrens.number}"></td>
                    <td><input type="text" name="money" readonly value="{$sanrens.money}"></td>
                    <td><input type="text" class="hejia2" name="hejia" value="{$hd_sum}" oninput="v3()">
                    </td>
                    <td><input type="text" name="beizhu" readonly value="{$sanrens.beizhu}"></td>
                </tr>
                {/volist}
            </table>
            <table class="layui-table" id="he6" style="display: none;">
                <tr>
                    <td>小计</td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" readonly></td>
                    <td><input type="text" value="{$row.sanren_money}" id="sanren_money"
                               name="sanren_money" class="sanren_money"></td>
                    <td><input type="text" value="{$row.sanren_hejia}" id="sanren_hejia"
                               name="sanren_hejia" class="sanren_hejia"></td>
                    <td><input type="text" readonly></td>
                </tr>
            </table>
            <!--<p>汇总</p>-->
            <div class="conts" style="display: none">
                <div class="input">
                    <span>费用合计</span>
                    <input type="text" readonly value="{$row.sr_heji}" name="sr_heji" id="sr_heji">
                </div>
            </div>
            <script>
                function v3() {
                    var hejias = $('.hejia2');
                    var benren_hejia = document.getElementById('sanren_hejia');
                    var br_heji = document.getElementById('sr_heji');
                    var hejia = 0;
                    for (var i = 0; i < hejias.length; i++) {
                        hejia += Number(hejias[i].value);
                    }
                    benren_hejia.value = hejia;
                    br_heji.value = hejia;
                }
            </script>
            <div class="conts" style="display: none">
                <div class="input">
                    <span>诉讼费</span>
                    <input type="text" readonly id="sanren_susong" value="{$row.sanren_susong}"
                           name="sanren_susong">
                </div>
                <div class="input">
                    <span>鉴定费</span>
                    <input type="text" readonly id="sanren_jianding" value="{$row.sanren_jianding}"
                           name="sanren_jianding">
                </div>
                <div class="input">
                    <span>公估费</span>
                    <input type="text" readonly id="sanren_gonggu" value="{$row.sanren_gonggu}"
                           name="sanren_gonggu">
                </div>
                <div class="input">
                    <span>住宿费</span>
                    <input type="text" readonly id="sanren_zhusu" value="{$row.sanren_zhusu}"
                           name="sanren_zhusu">
                </div>
                <div class="input">
                    <span>路桥费</span>
                    <input type="text" readonly id="sanren_luqiao" value="{$row.sanren_luqiao}"
                           name="sanren_luqiao">
                </div>
                <div class="input">
                    <span>燃油费</span>
                    <input type="text" readonly id="sanren_ranyou" value="{$row.sanren_ranyou}"
                           name="sanren_ranyou">
                </div>
                <div class="input">
                    <span>其他</span>
                    <input type="text" readonly id="sanren_qita" value="{$row.sanren_qita}"
                           name="sanren_qita">
                </div>
                <div class="input">
                    <span>合计</span>
                    <input type="text" readonly id="sanren_heji" value="{$row.sanren_heji}"
                           name="sanren_heji">
                </div>
            </div>


            <div class="conts" style="display: none">
                <div class="input">
                    <button style="margin: 1%;margin-top:20px;" onclick="sanzheren_bc()" type="button">保存
                    </button>
                </div>
            </div>
            <hr>
            <?php if( request()->controller()== "Bushen.hejia"){?>
            <div class="conts">
                <span style="width:98%;margin: 1%;">审核意见</span>
                <textarea name="" id="renshang_2_text" cols="30" rows="10"
                          style="width:98%;height: 100px;margin: 1%;"></textarea>
            </div>
            <div style="padding: 10px;display: flex;justify-content: center;">

                <button type="button" class="layui-btn layui-btn-danger" id="renshang_2">三者人伤通过审核
                </button>
                <!--<button type="button" class="layui-btn layui-btn-danger"  id="renshang_21">无损失</button>-->
                <!--<button type="button" class="layui-btn layui-btn-danger"  id="renshang_22">未参统</button>-->
                <!--<button type="button" class="layui-btn layui-btn-danger"  id="renshang_23">无需补偿</button>-->

                <button type="button" class="layui-btn layui-btn-warm" id="renshang_bk2">退回</button>


            </div>
            <?php }?>
            <script>
                $('#renshang_2').click(function () {
                    var renshang_2_text = $('#renshang_2_text').val();
                    if (renshang_2_text == '') {
                        layer.msg("请输入审核原因");
                        return false
                    }
                    layer.confirm('确定' + $(this).text() + '？', {
                        icon: 3,
                        title: $(this).text()
                    }, function (index) {
                        $.ajax({
                            url: "{:url('bushen/hejia/shenhe_post')}",
                            data: {
                                id: "{$orderid}",
                                bid: "{$bid}",
                                renshang_2: 3,
                                tuihui: renshang_2_text,
                            },
                            type: 'post',
                            dataType: 'json',
                            success: function (res) {
                                if (res.code == 1) {
                                    layer.msg(res.msg, {time: 2000}, function () {
                                        layer.closeAll()
                                        parent.layer.closeAll();
                                        parent.$("#table").bootstrapTable('refresh', {});
                                    });
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        })
                    });
                })

                $('#renshang_bk2').click(function () {
                    var renshang_2_text = $('#renshang_2_text').val();
                    if (renshang_2_text == '') {
                        layer.msg("请输入审核原因");
                        return false
                    }
                    layer.confirm('确定' + $(this).text() + '？', {
                        icon: 3,
                        title: $(this).text()
                    }, function (index) {
                        $.ajax({
                            url: "{:url('bushen/hejia/shenhe_post')}",
                            data: {
                                id: "{$orderid}",
                                bid: "{$bid}",
                                renshang_2: 2,
                                tuihui: renshang_2_text,
                            },
                            type: 'post',
                            dataType: 'json',
                            success: function (res) {
                                if (res.code == 1) {
                                    layer.msg(res.msg, {time: 2000}, function () {
                                        layer.closeAll()
                                        parent.layer.closeAll();
                                        parent.$("#table").bootstrapTable('refresh', {});
                                    });
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        })
                    });
                })
            </script>
        </div>

        <script>
            function sanzheren_bc() {
                var money = $('#sanren_money').val();
                var hejia = $('#sanren_money').val();
                var sr_heji = $('#sr_heji').val();
                var susong = $('#sanren_susong').val();
                var jianding = $('#sanren_jianding').val();
                var gonggu = $('#sanren_gonggu').val();
                var zhusu = $('#sanren_zhusu').val();
                var luqiao = $('#sanren_luqiao').val();
                var ranyou = $('#sanren_ranyou').val();
                var qita = $('#sanren_qita').val();
                var heji = $('#sanren_heji').val();
                var bid = $('#bid').val();
                $.ajax({
                    url: "{:url('buchang/sanzheren_bc')}",
                    data: {
                        sanren_money: money,
                        sanren_hejia: hejia,
                        sr_heji: sr_heji,
                        sanren_susong: susong,
                        sanren_jianding: jianding,
                        sanren_gonggu: gonggu,
                        sanren_zhusu: zhusu,
                        sanren_luqiao: luqiao,
                        sanren_ranyou: ranyou,
                        sanren_qita: qita,
                        sanren_heji: heji,
                        bid: bid
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        layer.msg(res.msg);
                    }
                })
            }
        </script>
        <div id="light2" class="white_content">
            <form action="" id="sanren_form">
                <input type="hidden" value="{$row.id}" name="id">
                <div class="conts">
                    <div class="input">
                        <span>诊断病情</span>
                        <input type="text" readonly name="bingqing" id="bingqing1" value="">
                    </div>
                    <div class="input">
                        <span>是否住院</span>
                        <select name="zhuyuan" id="zhuyuan1" disabled>
                            <option value="是">是</option>
                            <option value="否">否</option>
                        </select>
                    </div>
                    <div class="input">
                        <span>住院天数</span>
                        <input type="text" name="zhuyuan_date" readonly id="zhuyuan_date1" value="">
                    </div>
                    <div class="input">
                        <span>是否残疾</span>
                        <select name="canji" id="canji1" disabled>
                            <option value="是">是</option>
                            <option value="否">否</option>
                        </select>
                    </div>
                </div>
                <div class="content">
                    {if $sanren[0]['status'] eq 1}
                    <input type="button" onclick="sanren(this)" value="保存数据"
                           style="padding: 5px 10px;height:30px;border: none;background:#1b4fe7;color: #fff;">
                    {/if}
                    <input type="hidden" name="bid" class="sanid">
                    <table class="layui-table" id="tabProducts1">
                        <tr style="background: #4e73df;color:#fff;">
                            <td style="width: 66px;">选择</td>
                            <td>序号</td>
                            <!--<td>服务种类</td>-->
                            <td>费用类型</td>
                            <td>金额</td>
                            <td>数量</td>
                            <td>总价</td>
                            <td>核定金额</td>
                            <td>核定数量</td>
                            <td>核价金额</td>
                            <td>备注</td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" style="width: 15px;height: 15px;display: block;"
                                       name="id" readonly value=""/></td>
                            <td><input type="text" name="xuhao" value="1" readonly/></td>
                            <!--<td><input type="text" name="type" readonly/></td>-->
                            <td><input type="text" name="leixing" readonly/></td>
                            <td><input type="text" name="price" readonly/></td>
                            <td><input type="text" readonly name="num"/></td>
                            <td><input type="text" readonly name="money"/></td>
                            <td><input type="text" readonly name="hejia"/></td>
                            <td><input type="text" readonly name="hd_price"/></td>
                            <td><input type="text" readonly name="hd_num"/></td>
                            <td><input type="text" readonly name="beizhu"/></td>
                        </tr>
                    </table>
                    <table class="layui-table" id="hes1">
                        <tr>
                            <td>小计</td>
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly></td>
                            <!-- <td><input type="text" readonly></td> -->
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly name="money" id="sren_money" class="sren_money">
                            </td>
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly></td>
                            <td><input type="text" readonly name="hejia" id="sren_hejia" class="sren_hejia">
                            </td>
                            <td><input type="text" readonly></td>
                        </tr>
                    </table>

                </div>
                <script>
                    function v4() {
                        var price_he = $('.money100');
                        var num_he = $('.num100');
                        var hejias = $('.hejia10');

                        var money1 = new Array();
                        for (var i = 0; i < price_he.length; i++) {
                            money1[i] = price_he[i].value * num_he[i].value;
                            hejias[i].value = (money1[i]).toFixed(2);
                            ;
                        }
                        hejias = $('.hejia10');
                        console.log(hejias)
                        var bren_hejia = document.getElementById('sren_hejia');
                        var hejia = 0;
                        for (var i = 0; i < hejias.length; i++) {
                            console.log(hejias[i].value)
                            hejia += Number(hejias[i].value);
                        }
                        $(".sren_hejia").val(hejia);
                    }

                    function sanren(sub) {
                        layer.confirm('请确认是否已填完数据', {
                            icon: 3
                        }, function (index) {
                            var ids = $('.bid10');
                            var nums = $('.num100');
                            var moneys = $('.money100');
                            var hejias = $('.hejia10');
                            var bids = $('.sanid');
                            var id = new Array();
                            var num = new Array();
                            var money = new Array();
                            var hejia = new Array();
                            var sid = new Array();
                            for (var i = 0; i < ids.length; i++) {
                                id[i] = ids[i].value;
                            }
                            for (var i = 0; i < nums.length; i++) {
                                num[i] = nums[i].value;
                            }
                            for (var i = 0; i < moneys.length; i++) {
                                money[i] = moneys[i].value;
                            }
                            for (var i = 0; i < hejias.length; i++) {
                                hejia[i] = hejias[i].value;
                            }
                            $.ajax({
                                url: "{:url('bushen/hejia/hd_sanrens')}",
                                data: {
                                    id: id,
                                    num: num,
                                    money: money,
                                    hejia: hejia,
                                },
                                type: 'post',
                                dataType: 'json',
                                success: function (res) {
                                    layer.msg(res.msg);
                                    sub.onclick = '';
                                }
                            })
                        });
                    }
                </script>
                <div class="conts" style="display: flex;justify-content: center;">
                    <div class="">
                        <button style="margin: 1%;margin-top:20px;display: none;" type="button"
                                onclick="closeDialogs2()">保存
                        </button>
<!--                        <button style="margin: 1%;margin-top:20px;" type="button" onclick="closeDialog2()">-->
<!--                            关闭-->
<!--                        </button>-->
                    </div>
                </div>
        </div>
        </form>
    </div>
    <div id="fade2" class="black_overlay"></div>
    <script type="text/javascript">
        function openDialogs2(id) {
            // 1. 先打开弹窗（显示加载中状态）
            var $light2Content = $('#light2').contents(); // 先保存引用
            var layerIndex = layer.open({
                type: 1,
                title: '加载中...',
                content: `
                    <div style="
                      position: absolute;
                      top: 50%;
                      left: 50%;
                      transform: translate(-50%, -50%);
                      text-align: center;
                    ">
                      <i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
                      <p style="margin-top: 10px">加载中...</p>
                    </div>
                  `,
                end: function() {
                    // 弹窗关闭时，把内容放回 #light2
                    $('#light2').append($light2Content);
                },
                area: ['80%', '80%'],
                shadeClose: false // 禁止点击遮罩关闭
            });
            $.ajax({
                url: "{:url('bushen/lisuan/sanrens')}",
                data: {id: id},
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.status == true) {
                        var html = '';
                        if (res.data.renshang.length > 0) {
                            var html = '';
                            for (var i = 0; i < res.data.renshang.length; i++) {
                                html += "<tr>" +
                                    "<td><input type='checkbox' style='width: 15px;height: 15px;display: block;' name='id' class='bid10' disabled value=" + res.data.renshang[i].id + "></td>" +
                                    "<td><input type='text' class='xuhao10' name='xuhao' readonly value=" + res.data.renshang[i].xuhao + "></td>" +
                                    // "<td><input type='text' class='type10' name='type' readonly value=" + res.data.renshang[i].type + "></td>" +
                                    "<td><input type='text' class='leixing10' name='leixing' readonly value=" + res.data.renshang[i].leixing + "></td>" +
                                    "<td><input type='text' class='price10' name='price' readonly value=" + res.data.renshang[i].price + "></td>" +
                                    "<td><input type='text' class='num10' name='num' readonly value=" + res.data.renshang[i].num + "></td>" +
                                    "<td><input type='text' class='money10' name='money' readonly value=" + res.data.renshang[i].money + "></td>" +
                                    "<td><input type='text' class='money100' name='hd_price' oninput='v4()' value=" + res.data.renshang[i].hd_price + "></td>" +
                                    "<td><input type='text' class='num100' oninput='v4()' name='hd_num' value=" + res.data.renshang[i].hd_num + "></td>" +
                                    "<td><input type='text' class='hejia10' name='hejia' oninput='v4()' value=" + res.data.renshang[i].hejia + "></td>" +
                                    "<td><input type='text' class='beizhu10' name='beizhu' readonly value=" + res.data.renshang[i].beizhu + "></td>" +
                                    "</tr>";
                            }
                        } else {
                            html += "<tr>" +
                                "<td><input type='checkbox' style='width: 15px;height: 15px;display: block;' name='id' disabled value=''></td>" +
                                "<td><input type='text' name='xuhao' value='1' readonly></td>" +
                                // "<td><input type='text' name='type' readonly value=''></td>" +
                                "<td><input type='text' name='leixing' readonly value=''></td>" +
                                "<td><input type='text' name='price' readonly value=''></td>" +
                                "<td><input type='text' name='num' readonly value=''></td>" +
                                "<td><input type='text' name='money' readonly value=''></td>" +
                                "<td><input type='text' name='hejia' readonly value=''></td>" +
                                "<td><input type='text' name='beizhu' readonly value=''></td>" +
                                "</tr>";
                        }


                        $("#tabProducts1 tr").slice(1).remove();
                        $('#tabProducts1').append(html);
                        setTimeout(function(){
                            $('.bingqing1').val(res.data.sanren.bingqing);
                            $('.zhuyuan1').val(res.data.sanren.zhuyuan);
                            $('.zhuyuan_date1').val(res.data.sanren.zhuyuan_date);
                            $('.canji1').val(res.data.sanren.canji);
                            // $('#sren_money').val(res.data.sanren.money);
                            // $('#sren_hejia').val(res.data.sanren.hejia);
                            $('.sanid').val(res.data.sanren.id);

                            var money10 = $('.money10');
                            var hejia10 = $('.hejia10');
                            var sum = 0;
                            for (var i = 0; i < money10.length; i++) {
                                sum += Number(money10[i].value);
                            }
                            $('.sren_money').val(sum.toFixed(2));
                            sum = 0;
                            for (var i = 0; i < hejia10.length; i++) {
                                sum += Number(hejia10[i].value);
                            }
                            $('.sren_hejia').val(sum.toFixed(2));
                        },200)





                        layer.title('详情', layerIndex); // 修改标题
                        // $('#layui-layer' + layerIndex).find('.layui-layer-content').html($('#light2').html()); // 更新内容
                        $('#layui-layer' + layerIndex)
                            .find('.layui-layer-content')
                            .empty() // 先清空目标容器
                            .append($('#light2').contents()); // 移动 #light2 的子节点（不复制）
                    }else{
                        layer.msg(res.msg || '数据加载失败', {icon: 2});
                    }
                }
            })
        }

        function closeDialogs2() {
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "{:url('sanche/renshangss')}",//url
                data: $('#sanren_form').serialize(),
                success: function (res) {
                    // console.log(res.ress);//打印服务端返回的数据(调试用)
                    layer.msg(res.msg);
                    if (res.status == true) {
                        var html = '';
                        if (res.ress.length > 0) {
                            for (var i = 0; i < res.ress.length; i++) {
                                html += "<tr>" +
                                    "<td><input type='checkbox' style='width: 15px;height: 15px;display: block;' readonly name='id' value=" + res.ress[i].id + "></td>" +
                                    "<td><input type='text' name='type' readonly value=" + res.ress[i].type + "></td>" +
                                    "<td><input type='text' name='name' readonly onclick='openDialogs2( + res.ress[i].id + )' style='text-decoration: underline;color:blue;cursor: pointer;' value=" + res.ress[i].name + "></td>" +
                                    "<td><input type='text' name='sex' readonly value=" + res.ress[i].sex + "></td>" +
                                    "<td><input type='text' name='age' readonly value=" + res.ress[i].age + "></td>" +
                                    "<td><input type='text' name='quality' readonly value=" + res.ress[i].quality + "></td>" +
                                    "<td><input type='text' name='nuit' readonly value=" + res.ress[i].nuit + "></td>" +
                                    "<td><input type='text' name='num' readonly value=" + res.ress[i].number + " ></td>" +
                                    "<td><input type='text' name='money' readonly value=" + res.ress[i].money + "></td>" +
                                    "<td><input type='text' name='hejia' class='hejia2' oninput='v3()' value=" + res.ress[i].hejia + "></td>" +
                                    "<td><input type='text' name='beizhu' readonly value=" + res.ress[i].beizhu + "></td>" +
                                    "</tr>";
                            }
                            $("#tabProduct6 tr").slice(1).remove();
                            $('#tabProduct6').append(html);
                            v3();
                        }
                    }
                },
            });
            $("#light2").css("display",'none')
            $("#fade2").css("display",'none')
        }

        function closeDialog2() {
            $("#light2").css("display",'none')
            $("#fade2").css("display",'none')
        }
    </script>

</div>